package com.quanyue.music.file.service.impl;

import com.quanyue.auto.util.AssertUtils;
import com.quanyue.music.domain.entity.MusicTag;
import com.quanyue.music.file.mapper.MusicTagMapper;
import com.quanyue.music.file.service.MusicTagService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class MusicTagServiceImpl implements MusicTagService {
    @Autowired
    private MusicTagMapper musicTagMapper;

    @Override
    public void add(MusicTag musicTag) {
        musicTag.setCreateTime(LocalDateTime.now());
        musicTag.setModifyTime(LocalDateTime.now());
        musicTag.setDelFlag(false);
        musicTagMapper.insert(musicTag);
    }

    @Override
    public void update(MusicTag musicTag) {
        MusicTag checkSort = musicTagMapper.findOne(musicTag.getId());
        AssertUtils.notNull(checkSort, "没有该分类");
        musicTag.setCreateTime(checkSort.getCreateTime());
        musicTag.setModifyTime(LocalDateTime.now());
        musicTag.setDelFlag(false);
        musicTagMapper.update(musicTag);
    }

    @Override
    public void delete(String id) {
        MusicTag musicTag = new MusicTag();
        musicTag.setId(id);
        musicTag.setDelFlag(true);
        musicTag.setModifyTime(LocalDateTime.now());
        musicTagMapper.updateSelective(musicTag);
    }

    @Override
    public List<MusicTag> findList() {
        return musicTagMapper.findAllValid();
    }
}
